/**
 * @NApiVersion 2.x
 * @NScriptType MapReduceScript
 */
define(
    ['N/record','N/search',"N/runtime"],
    function(record, search,runtime) {

        function getInputData() {
            var mySearch;
            try{
                var pageSize = runtime.getCurrentScript().getParameter('custscript_so_source_delete_page_size');
                mySearch = search.load({id: "customsearch_need_delete_so_source"});
                return mySearch.run().getRange({start:0,end:parseInt(pageSize)});
            }catch(e){
                log.error({title:'e',details:JSON.stringify(e)});
            }
        }

        function map(context) {
            /*log.debug({
                title: 'context',
                details: JSON.stringify(context)
            });*/
            try {
                var sourceId = JSON.parse(context.value).id;
                record.delete({ type: 'customrecord_platform_so_source', id: sourceId });
                log.audit({title:sourceId,details:"删除成功 "});
            }catch (e){
                log.error({title:sourceId,details:"删除失败 "+JSON.stringify(e)});
            }

        }

        function reduce(context) {
            log.debug({
                title: 'context',
                details: context
            });
        }

        function summarize(summary) {

        }
        return {
            getInputData: getInputData,
            map: map,
            reduce: reduce,
            summarize: summarize
        };
    });